﻿@{
    Layout = null;
}
@model System.Collections.IEnumerable
<!DOCTYPE html>
<html>
@Html.Partial("LoadPanelPartial")
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title></title>
    @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/json2.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

@Html.DevExpress().GetStyleSheets(
         new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme }
)


@Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)



<script type="text/javascript">

    function MenuTop_emClick(source, e) {
        var templateClsID = $('#hidTemplateClsID').val();
        switch (e.item.name) {
            case "btnWord":
                {
                    window.open(rootPath + "/Admin/SysTemplate/OfficeTemplate?temClsID=" + templateClsID + "&temType=W", "temWord");
                    break;
                }
            case "btnExcel":
                {
                    window.open(rootPath + "/Admin/SysTemplate/OfficeTemplate?temClsID=" + templateClsID + "&temType=E", "temExcel");
                    break;
                }
            case "btnPPT":
                {
                    window.open(rootPath + "/Admin/SysTemplate/OfficeTemplate?temClsID=" + templateClsID + "&temType=P", "temPPT");
                    break;
                }
            case "btnHtml":
                {
                    window.open(rootPath + "/Admin/SysTemplate/HtmlTemplate?temClsID=" + templateClsID, "temHtml");
                    break;
                }
            case "btnDelMany":
                {
                    lpModal.Show();
                    var idArray = "";
                    var idList = "";
                    $(':checkbox[id^="cb_"]:checked').each(function () {
                        idArray = $(this).attr('id').split('_');
                        if (idArray.length == 3) {
                            if (idList == "") {
                                idList += idArray[1];

                            }
                            else {
                                idList +="," + idArray[1];
                            }
                        }
                    });

                    if (idList == "") {
                        alert("请选择要删除的数据");
                        lpModal.Hide();
                    } else {
//                        temListJson = JSON.stringify(temList);
                        if (window.confirm("确定删除选择的数据")) {
                            $.ajax({
                                type: 'POST',
                                url: rootPath + '/Admin/SysTemplate/DelMany',
                                data: { idList: idList },
                                success: function (result) {
                                    if (result == "ok") {
                                        alert("删除成功");
                                        //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
                                        window.location.href = window.location.href;
                                    } else if (result == "error") {
                                        alert("删除失败");
                                        lpModal.Hide();
                                    } else {
                                        alert("参数错误");
                                        lpModal.Hide();
                                    }

                                }
                            });


                        } else {
                            lpModal.Hide();
                        }
                    }


                    break;
                }
        }
    }

    var editObjTable = null;
    function templateEdit(temClsID, temClsType, obj) {
        editObjTable = $(obj).parent().parent().parent();
        if (temClsType == "") //类别
        {
        } else if (temClsType == "H") {
            window.open(rootPath + "/Admin/SysTemplate/HtmlTemplate?temClsID=" + $('#hidTemplateClsID').val() + "&temID=" + temClsID, "temHtml");
        } else {
            window.open(rootPath + "/Admin/SysTemplate/OfficeTemplate?temClsID=" + $('#hidTemplateClsID').val() + "&temType=" + temClsType + "&temID=" + temClsID, "temOffice");
        }

    }

    function templateDbClick(temClsID, temClsType) {
        if (temClsType == "") //类别
        {
            //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + temClsID;
            window.location.href = window.location.href;
        }
        else if (temClsType == "H") {
            window.open(rootPath + "/Admin/SysTemplate/HtmlTemplateRead?temID=" + temClsID, "temHtmlRead");
        } else {
            window.open(rootPath + "/Admin/SysTemplate/OfficeTemplateRead?temID=" + temClsID, "temHOfficeRead");
        }
    }


    function templateDel(temClsID, temClsType) {
        if (window.confirm("确定删除")) {
            $.ajax({
                type: 'POST',
                url: rootPath + '/Admin/SysTemplate/DelTemplate',
                data: { temID: temClsID },
                success: function (result) {
                    if (result == "ok") {
                        alert("删除成功");
                        //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
                        window.location.href = window.location.href;
                    }
                    else if (result == "error") {
                        alert("删除失败");
                    }
                    else {
                        alert(result);
                    }
                }
            });
        }
        
    }

    function selectAll(obj) {
        var isSelect = $(obj).is(':checked');
        $(':checkbox[id^="cb_"]').attr("checked", isSelect);
    }


    function createHtmlOK() {
        //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
        window.location.href = window.location.href;
    }

    function createHtmlEditOK(name) {
        if (null != editObjTable) {
            $(editObjTable).find('tr').eq(0).find('img').attr('alt', name);
            if (name.length > 11) {
                name = name.substring(0, 11) + "...";
            }
            $(editObjTable).find('tr').eq(1).find('td').eq(0).html(name);
        } else {
            //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
            window.location.href = window.location.href;
        }
    }


    function createOfficeOK(createOfficeType) {
        if (createOfficeType == "add") {
            //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
            window.location.href = window.location.href;
        } else {
            if (null != editObjTable) {
                $(editObjTable).find('tr').eq(0).find('img').attr('alt', createOfficeType);
                if (createOfficeType.length > 11) {
                    createOfficeType = createOfficeType.substring(0, 11) + "...";
                }
                $(editObjTable).find('tr').eq(1).find('td').eq(0).html(createOfficeType);
            } else {
                //parent.window.location.href = rootPath + "/Admin/SysTemplate/Index?focusNodeName=" + $('#hidTemplateClsID').val();
                window.location.href = window.location.href;
            }
        }
    }


</script>
</head>
<body> 
<div class="floatToolMenu" id="toolMenu">
  @Html.DevExpress().Menu(settings =>
{
    settings.Name = "toolBarMenu";
    settings.ItemAutoWidth = false;
    settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
    settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
    settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

    settings.Items.Add(item =>
    {
        item.Name = "btnAddTemplate";
        item.Text = "增加模板";
        item.ClientEnabled = true;
        item.Image.Url = Url.Content("~/Content/ControlImages/templates.png");
        if (ViewData["ShowWEP"].ToString() == "A")
        {
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnWord";
                childItem.Text = "WORD模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/word.png");
            });
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnExcel";
                childItem.Text = "EXCEL模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/excel.png");
            });
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnPPT";
                childItem.Text = "PPT模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/ppt.png");
            });
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnHtml";
                childItem.Text = "HTML模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/html.png");
            });
        }
        else if (ViewData["ShowWEP"].ToString() == "H")
        {
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnHtml";
                childItem.Text = "HTML模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/html.png");
            });
        }
        else
        {
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnWord";
                childItem.Text = "WORD模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/word.png");
            });
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnExcel";
                childItem.Text = "EXCEL模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/excel.png");
            });
            item.Items.Add(childItem =>
            {
                childItem.Name = "btnPPT";
                childItem.Text = "PPT模板";
                childItem.ClientEnabled = true;
                childItem.Image.Url = Url.Content("~/Content/ControlImages/ppt.png");
            });
        }

    });


    settings.Items.Add(item =>
    {
        item.Name = "btnSelectAll";
        item.ClientEnabled = true;
        item.SetTextTemplateContent("<input type='checkbox' id='selectAllChk' onclick='selectAll(this);' />");

    });

    settings.Items.Add(item =>
    {
        item.Name = "btnDelMany";
        item.Text = "批量删除";
        item.ClientEnabled = true;
        item.Image.Url = Url.Content("~/Content/ControlImages/addNext.png");
        item.ItemStyle.ForeColor = System.Drawing.Color.Red;
    });

    settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
    settings.ItemLinkMode = ItemLinkMode.ContentBounds;
}).GetHtml()
</div>
<div>
<table width="99%" align="center">
@{
    List<ElingOA6_Admin_DSJCJ.Model.SysTemplate> list = Model as List<ElingOA6_Admin_DSJCJ.Model.SysTemplate>;
    string chkID = string.Empty;
    int begin = 0;
    int step = 5;
    int end = begin + step;
    int count = list.Count;
    if (count < end)
    {
        end = count;
    }
    ElingOA6_Admin_DSJCJ.Model.SysTemplate temMdoel;
    while (begin < count)
    {
        <tr>
       @for (int i = begin; i < end; i++)
       {
           temMdoel = list[i];
           chkID = "cb_" + temMdoel.FTemplateID + "_" + temMdoel.FTemplateType;
            <td width="19%"><table width="100%">
            <tr>
                <td align="center"><img src="@Url.Content("~" + temMdoel.TemImg)" alt="@temMdoel.ShortName" style="cursor:pointer" ondblclick="templateDbClick('@temMdoel.FTemplateID','@temMdoel.FTemplateType')" /></td>
            </tr>  
            <tr>
                <td align="center">@temMdoel.ShortName</td>
            </tr>
            <tr>
                <td align="center"><input type="checkbox" id="@chkID"+ />&nbsp;<span onclick="templateEdit('@temMdoel.FTemplateID','@temMdoel.FTType',this)" style="cursor:pointer">[修改]</span>&nbsp;<span style="cursor:pointer; color:Red;" onclick="templateDel('@temMdoel.FTemplateID','@temMdoel.FTType')">[删除]</span></td>
            </tr>  
            </table></td>
       }

        @if (end - begin != step)
        {
            <td width="19%">&nbsp;</td>
        }
        
        </tr>

   
        begin = end;
        end = begin + step;
        if (end > count)
        {
            end = count;
        }

    }
    
    
}
</table>
</div>

@Html.Hidden("hidTemplateClsID", ViewData["templateClsID"])
<script>
    lp.Hide();
</script>
</body>
</html>
